import os
import tempfile

# 获取临时文件夹路径
temp_dir = tempfile.gettempdir()

print(f"临时文件夹路径: {temp_dir}")

file_path = "D:/eeeeeeeee/ep436.rar"
# 获取当前文件路径
current_file_path = os.path.dirname(file_path)
# 获取文件名
basename = os.path.basename(file_path)

# 获取文件名（不包含路径和扩展名）
file_name = os.path.splitext(basename)[0]

# 创建缓存路径
folder_path = temp_dir + "/" + "BaiDuSync/" + file_name + "Temp"
# 创建存储切片文件的文件夹，如果文件夹不存在
if not os.path.exists(folder_path):
    os.makedirs(folder_path)

with open(file_path, 'rb') as f:
    size = os.path.getsize(file_path)
    chunk_size = 4 * 1024 * 1024
    if size > chunk_size:
        index = 0
        chunk = f.read(chunk_size)
        while chunk:
            chunk_file_path = os.path.join(folder_path, f"{basename}.{chunk_size}.{index}")
            with open(chunk_file_path, 'wb') as chunk_file:
                chunk_file.write(chunk)
                index += 1
                chunk = f.read(chunk_size)